package com.sfh.dog.adapter;

import java.util.ArrayList;
import java.util.List;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.sfh.dog.DogApplication;
import com.sfh.dog.R;
import com.sfh.dog.entity.Daily;
import com.sfh.dog.entity.Review;
import com.sfh.dog.http.APIConfig;
import com.sfh.dog.util.FaceUtil;
import com.sfh.dog.util.PhotoUtil;

import android.content.Context;
import android.graphics.Bitmap.Config;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 评论
 * 
 * @version [版本号2014-3-28]
 */
public class ReviewAdapter extends LBaseAdapter<Review, ReviewAdapter.HondlerView>
{
    public interface IReview
    {
        public void onClick(String id, boolean isOK);
    }
    
    private IReview mReview;
    
    private List<Review> mEntities;
    
    public void setEntities(List<Review> data, boolean isAdd)
    {
        if (!isAdd)
        {
            this.mEntities.clear();
        }
        
        if (null != data && data.size() > 0)
        {
            System.err.println("entities.size() =" + data.size());
            this.mEntities.addAll(data);
            notifyDataSetChanged();
        }
        
    }
    
    public ReviewAdapter(Context context, IReview review, List<Review> entities)
    {
        super(context, R.layout.daily_review_item, entities);
        this.mReview = review;
    }
    
    static class HondlerView
    {
        public ImageView ivDogPhoto;
        
        public TextView tvName;
        
        public TextView tvNumber;
        
        public TextView tvContent;
        
        public TextView tvTime;
        
    }
    
    @Override
    public HondlerView findHondView(View view)
    {
        HondlerView mHondlerView = new HondlerView();
        mHondlerView.ivDogPhoto = (ImageView)view.findViewById(R.id.ivDogphoto);
        mHondlerView.tvName = (TextView)view.findViewById(R.id.tvName);
        mHondlerView.tvTime = (TextView)view.findViewById(R.id.tvTime);
        mHondlerView.tvNumber = (TextView)view.findViewById(R.id.tvNumber);
        mHondlerView.tvContent = (TextView)view.findViewById(R.id.tvContent);
        return mHondlerView;
    }
    
    @Override
    public void setViewData(Review t, HondlerView hondler, int position)
    {
        
        hondler.tvName.setText("");
        
        hondler.tvContent.setText(FaceUtil.replace(mContext, t.getContent()));
        
        hondler.tvTime.setText(t.getCreatedAt());
        hondler.tvNumber.setText(String.format("%sF", position));
        
        //    mHondlerView.ivDogPhoto.setTag(entity.dogID);
        
        //        mHondlerView.ivDogPhoto.setOnClickListener(new View.OnClickListener()
        //        {
        //            @Override
        //            public void onClick(View v)
        //            {
        //                //              DogApplication.gotoBlogUI(v.getContext(),
        //                //                      String.valueOf(v.getTag()));
        //            }
        //        });
        
    }
}
